﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using VOL.Core.Utilities;
using VOL.Entity.DomainModels;
using VOL.Smartmanufacturing;
using VOL.Smartmanufacturing.DTO.Bom;
using VOL.Smartmanufacturing.IServices;

namespace VOL.WebApi.Controllers
{
    /// <summary>
    /// 物料管理控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialManagementController : ControllerBase
    {
        /// <summary>
        /// bom接口
        /// </summary>
        private readonly IBOMService ibomService;

        public MaterialManagementController(IBOMService ibomService)
        {
            this.ibomService = ibomService;
        }

        [HttpGet]
        /// <summary>
        /// 显示bom数据
        /// </summary>
        /// <param name="getBomDto">查询分页参数</param>
        /// <returns></returns>
        public async Task<WebResponseContent> GetBom([FromQuery]GetBomDto getBomDto)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            var result = await ibomService.GetBom(getBomDto);
            return webResponseContent.OK("数据查询成功", result);
        }
        [HttpPost]
        /// <summary>
        /// 添加Bom
        /// </summary>
        /// <param name="bom"></param>
        /// <returns></returns>
        public async Task<WebResponseContent> AddBom(BOM bom)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            var result = await ibomService.AddBom(bom);
            return webResponseContent.OK("添加bom数据成功", result);
        }
        [HttpDelete]
        /// <summary>
        /// 删除Bom
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public async Task<WebResponseContent> DelBom(string ids)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            var result = await ibomService.DelBom(ids);
            return webResponseContent.OK("删除bom数据成功", result);
        }
        [HttpPut]
        /// <summary>
        /// 修改bom数据
        /// </summary>
        /// <param name="bom">bom实体</param>
        /// <returns></returns>
        public async Task<WebResponseContent> UpDateBom(BOM bom)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            var result = await ibomService.UpDateBom(bom);
            return webResponseContent.OK("修改bom数据成功", result);
        }

    }
}
